//
//  BaseNavigationController.m
//  TraderMobileKYi
//
//  Created by shijiezhao on 9/6/17.
//  Copyright © 2017年 com.yeezsoft.init. All rights reserved.
//

#import "EBMBaseNavigationController.h"

@interface EBMBaseNavigationController ()

@end

@implementation EBMBaseNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    // 创建视图
    [self initView];
}



#pragma mark -- --------------------创建视图--------------------
// 创建视图
- (void)initView
{
    // 设置属性
    [self settingAttribute];
    
   
}

#pragma mark -- --------------------设置属性--------------------
// 设置属性
- (void)settingAttribute
{
    // 设置背景颜色
    self.navigationBar.translucent = NO;
    self.navigationBar.barTintColor = RGBCOLOR16_1c1e24;
    [self.navigationBar setShadowImage:[UIImage new]];
    
    // 设置字体颜色
    NSDictionary *attributeDic = @{NSFontAttributeName:Font_17,
                                   NSForegroundColorAttributeName:RGBACOLOR16_fffff_80};
    self.navigationBar.titleTextAttributes = attributeDic;
    
    
    //  设置导航栏颜色渐变
    [self setNavigationTintColor];
    
    
}

//  设置导航栏颜色渐变
- (void)setNavigationTintColor
{
    
    CGRect frame = CGRectMake(0, 0, KScreenWidth, KNavigationBarAndStatusBarHeight);
    
    UIImageView *imgview = [[UIImageView alloc]initWithFrame:frame];
    
    UIGraphicsBeginImageContext(imgview.frame.size);
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
    
    CGContextScaleCTM(context, frame.size.width, frame.size.height);
    
    CGFloat colors[] = {
        
        28/255.0, 30/255.0, 36/255.0, 1.0,
        
        61/255.0, 64/255.0, 68/255.0, 1.0,
        
    };
    
    CGGradientRef backGradient = CGGradientCreateWithColorComponents(rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4));
    
    CGColorSpaceRelease(rgb);
    
    //设置颜色渐变的方向，范围在(0,0)与(1.0,1.0)之间，如(0,0)(1.0,0)代表水平方向渐变,(0,0)(0,1.0)代表竖直方向渐变
    
    CGContextDrawLinearGradient(context, backGradient, CGPointMake(0, 0), CGPointMake(1.0, 0), kCGGradientDrawsBeforeStartLocation);
    
    [self.navigationBar setBackgroundImage:UIGraphicsGetImageFromCurrentImageContext()  forBarMetrics:UIBarMetricsDefault];
}



#pragma mark --------------方法--------------

//  VC在navig中时由导航栏设置状态栏，此方法将navig的设置权交于VC       父类的方法
- (UIStatusBarStyle)preferredStatusBarStyle
{
    UIViewController *viewController = self.topViewController;
    return [viewController preferredStatusBarStyle];
}


//  隐藏标签栏
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    dispatch_async(dispatch_get_main_queue(), ^{
        if(self.viewControllers.count>0)
        {
            viewController.hidesBottomBarWhenPushed = YES;
        }
        
        [super pushViewController:viewController animated:animated];
    });
    
    
}




@end
